//
//  GZNavigationBar.m
//  GongZheng
//
//  Created by huan on 2018/4/26.
//  Copyright © 2018年 huan. All rights reserved.
//

#import "GZNavigationBar.h"

@interface GZNavigationBar ()

@property (nonatomic, strong) UILabel *titleLabel;

@property (nonatomic, strong) UIView *line;

@end

@implementation GZNavigationBar

+ (instancetype)navigationBar {
    GZNavigationBar *navigationBar = [[self alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT == 812 ? NavigationBar_HEIGHT_X : NavigationBar_HEIGHT)];
    navigationBar.backgroundColor = [UIColor yellowColor];
    return navigationBar;
}

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setupUI];
    }
    return self;
}

- (void)setupUI {

    self.leftButton.frame = CGRectMake(AdjustWidth(10), 0, AdjustWidth(70), 44);
  
    
    self.rightButton.frame = CGRectMake(self.width - AdjustWidth(110), 0, AdjustWidth(110), 44);
    
    self.titleLabel.frame = CGRectMake(AdjustWidth(110), SCREEN_HEIGHT == 812 ? 44 : 20, SCREEN_WIDTH - AdjustWidth(220), 44);
    
    self.leftButton.centerY = self.titleLabel.centerY;
    
    self.line.frame = CGRectMake(0,self.height - 1, self.width, 1);

}

//设置title颜色
- (void)setTitleColor:(UIColor *)titleColor{
    self.titleLabel.textColor = titleColor;
}

//设置左边按钮的的图片
- (void)setLeftBtnImageName:(NSString *)imageName{
    [self.leftButton setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    [self.leftButton setImage:[UIImage imageNamed:imageName] forState:UIControlStateHighlighted];
}

- (void)setTitleString:(NSString *)titleString {
    _titleString = [titleString copy];
    self.titleLabel.text = titleString;
}

- (void)setNotShowLeft:(BOOL)notShowLeft {
    _notShowLeft = notShowLeft;
    self.leftButton.hidden = notShowLeft;
}

- (void)setShowRight:(BOOL)showRight {
    _showRight = showRight;
    self.rightButton.hidden = !showRight;
}

#pragma mark - layzLoad
- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        _titleLabel.font = GZFont(GZTitleFontSize);
        _titleLabel.textColor = [UIColor whiteColor];
        [self addSubview:_titleLabel];
    }
    return _titleLabel;
}

- (UIView *)line {
    if (!_line) {
        _line = [[UIView alloc] init];
        _line.backgroundColor = [UIColor lineColor];
        _line.alpha = 0.6;
        _line.hidden = YES;
        [self addSubview:_line];
    }
    return _line;
}

- (UIButton *)leftButton {
    if (!_leftButton) {
        _leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_leftButton setImage:[UIImage imageNamed:@"GZBack"] forState:UIControlStateNormal];
        [_leftButton setImage:[UIImage imageNamed:@"GZBack"] forState:UIControlStateHighlighted];
        [_leftButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _leftButton.titleLabel.font = GZFont(GZContentFontSize);
      
        [self addSubview:_leftButton];
    }
    return _leftButton;
}

- (UIButton *)rightButton {
    if (!_rightButton) {
        _rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_rightButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _rightButton.titleLabel.font = GZFont(GZContentFontSize);
        _rightButton.hidden = YES;
        _rightButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
      
    }
    return _rightButton;
}


- (RACSubject *)leftClickSubject {
    if (!_leftClickSubject) {
        _leftClickSubject = [RACSubject subject];
    }
    return _leftClickSubject;
}

- (RACSubject *)rightClickSubject {
    if (!_rightClickSubject) {
        _rightClickSubject = [RACSubject subject];
    }
    return _rightClickSubject;
}

@end
